<%--
    Document   : index
    Created on : Oct 25, 2009, 10:09:20 PM
    Author     : Phong
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
<%@ page import="java.sql.*" %>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

        <link rel="stylesheet" href="css/style.css" />
        <link rel="stylesheet" href="css/front.css"  />


        <title>Themes</title>
    </head>


    <body bgcolor="#154978">

        <table width="1024" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" align="center">
            <!--DWLayoutTable-->
            <tr>
                <td width="1024" height="157" valign="top" background="images/Banner.jpg">

                </td>
            </tr>
            <tr>
                <td height="463" valign="top">
                    <table width="100%" border="0" cellpadding="2" cellspacing="2">
                        <!--DWLayoutTable-->
                        <tr>
                            <td height="39" colspan="3" valign="top" background="images/button/bg_login.gif">

                                <%@include file="include/loginBar.jsp" %>c       </td>
                        </tr>
                        <tr>
                            <td width="140" rowspan="2" valign="top">
                                <jsp:include page="menu_left.jsp" />
                            </td>
                            <td width="670" rowspan="2" align="left"  valign="top" bgcolor="#CCCCCC">
                                <table width="680">
                                    <form action="SaveTest.jsp" name="myform" method="post" >

                                        <jsp:useBean id="Obj" class="DAO.DAOQuery" scope="request" />
                                        <!-- Kiem tra cau hoi  -->
                                        <%
            int QuestionTrue = 0;
            int idQuestion;
            float Mark = 0;
            String calcucator = "";
            boolean test = false;
            String[] Question = null;
            String[] checkedID = null;
            String checkedString = "";
            int checkUser = 0;
            checkedID = request.getParameterValues("Choice");
            Question = request.getParameterValues("QuestionID");
            if (checkedID != null) {
                for (int k = 0; k < checkedID.length; k++) {
                    checkUser = Integer.parseInt(checkedID[k]);
                                        %>
                                        <input type="hidden" value="<%=checkUser%>" name="choiceUser">
                                        <%
                    checkedString += checkedID[k] + ",";
                }
                checkedString = checkedString.substring(0, checkedString.length() - 1);
            }

            for (int i = 0; i < Question.length; i++) {
                idQuestion = Integer.parseInt(Question[i]);
                int DEFAULTTRUE = Obj.counterRowTrue(idQuestion);
                int DEFAULTFALSE = Obj.counterRowFalse(idQuestion);
                int KICKTRUE = Obj.counterCheckTrue(idQuestion, checkedString);
                int KICKFALSE = Obj.counterCheckFalse(idQuestion, checkedString);
                ResultSet rs = Obj.checkTest(idQuestion, checkedString);
                if (rs.next()) {
                    if (DEFAULTTRUE == KICKTRUE && DEFAULTFALSE != KICKFALSE && KICKFALSE != 1 && KICKFALSE != 2 && KICKFALSE != 3 && KICKFALSE != 4) {
                        QuestionTrue++;
                        calcucator += Question[i] + ",";
                        test = true;
                    } else {
                        //out.println("Ban da tra loi sai");
                    }

                }
            }
            //out.println("Ban da tra loi dung : " + QuestionTrue + "/" + Question.length);
                                        %>
                                        <p style="font-size:17px">Ban da tra loi dung : <%=QuestionTrue%> / <%=Question.length%></p>
                                        <!-- The End -->

                                        <!-- Tinh Diem Cua Nguoi Dung Kick Dung-->
                                        <%
            if (test == true) {
                calcucator = calcucator.substring(0, calcucator.length() - 1);
                ResultSet rs = Obj.calculatorMark(calcucator);
                while (rs.next()) {
                    Mark += rs.getFloat("Mark");
                }
                                        %>
                                        <p style="font-size:18px">Ban duoc so diem la : <%=Mark%></p>
                                        <%
            } else {
                                        %>
                                        <p style="font-size:18px">Ban duoc so diem la : <%=Mark%></p>
                                        <%
            }
                                        %>
                                        <!-- The End -->
                                        <p style="font-size:18px;color:red">Dap an ma ban da tra loi : </p>

                                        <!-- Hien Thi Cau Nguoi Tra Loi -->
                                        <%
                                       // out.println(request.getParameter("Testid"));
            int subID = Integer.parseInt(request.getParameter("subid"));
            for (int id = 0; id < Question.length; id++) {
                idQuestion = Integer.parseInt(Question[id]);
                //  out.println(idQuestion);

                ResultSet rs = Obj.selectQuestionLast(subID, idQuestion);
                if (rs.next()) {
                                        %>
                                        <P style="font-size:18px"> <%=rs.getString("ContentQuestion")%></P>
                                        <input type="hidden" name="QuestionID" value="<%=idQuestion%>">
                                        <%

                    ResultSet rss = Obj.selectAnswerLast(idQuestion);

                    while (rss.next()) {
                        int answerId = rss.getInt("AnswerID");
                        //ResultSet rs1 = Obj.selectAnswerTrue(idQuestion);
                        //  while (rs1.next()) {

                        //   }
                        //out.println(rss.getInt("AnswerID"));
                                        %>
                                        <input type="checkbox" name="Choice" disabled="true"<%
                        if (checkedID != null) {
                            for (int k = 0; k < checkedID.length; k++) {
                                checkedString = checkedID[k];
                                if (rss.getString("AnswerID").equals(checkedString)) {
                                               %>
                                               checked="checked" 
                                               <%                                }
                            }
                        }
                                               %>
                                               />
                                        <%

                        if (rss.getInt("TrueOrFalse") == 1) {%><b style="color:red">  <%=rss.getString("AnswerContent")%></b><br>
                                        <%
                                               } else {
                                        %>
                                        <%=rss.getString("AnswerContent")%><br>
                                        <%
                        }

                    }
                }
            }
           // out.println(request.getParameter("Test"));

                                        %>
                                        <!-- The End -->    
                                        <br>

                                        <input type="hidden" value="<%=Mark%>" name="Mark">
                                        <input type="hidden" value="<%=QuestionTrue%>" name="AnswerTrue">
                                        <input type="hidden" value="<%=request.getParameter("Testid")%>" name="TestID">
                                        <input type="hidden" value="<%=request.getParameter("UserName")%>" name="Name">
                                        <input type="hidden" value="<%=request.getParameter("timeStart")%>" name="StartTime">
                                        <input type="hidden" value="<%=request.getParameter("timeEnd")%>" name="EndTime">
                                        <input type="hidden" value="1" name="Status">
                                        <input type="submit" value="Lưu bài lên máy chủ">
                                    </form>
                                </table>
                            </td>

                        </tr>

                    </table>
                </td>
            </tr>
        </table>
    </body>
</html>
